#pragma once

#include <iostream>
#include "Protocol.hpp"


class Calculator
{
public:
    Calculator()
    {

    }
    Response Execute(const Request& req)
    {
        //我们拿到就是结构化数据
        Response resp;
        switch(req.Oper())
        {
        case '+':
            resp.SetResult(req.X() + req.Y());
            break;
        case '-':
            resp.SetResult(req.X() - req.Y());
            break;
        case '*':
            resp.SetResult(req.X() * req.Y());
            break;
        case '/':
            {
                if(req.Y() == 0)
                {
                    resp.SetCode(1);//1 就是除0
                }
                else
                {
                    resp.SetResult(req.X() + req.Y());
                }   
            }
            break;
        case '%':
            {
                if(req.Y() == 0)
                {
                    resp.SetCode(2);//2 就是模0
                }
                else
                {
                    resp.SetResult(req.X() % req.Y());
                }   
            }
            break;
        default:
            resp.SetCode(3);//3 就是没有操作
            break;
        }
        return resp;
    }
    ~Calculator()
    {

    }
private:

};



